import React, { Component,PropTypes } from 'react';
import CommonBtn from '../../Component/CommonComponent/CommonBtn';
import '../../Stylesheets/wx/comfirmPayMoney.css';
import {ToBcPay,QueryPayResult} from '../../Action/auth';
import {GetQueryString} from '../../Action/rpc';
import DelayModal from '../../Component/CommonComponent/DelayModal'

export default class ToPayStatus extends Component {
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {
            bcMessage:'',
            toPaySuccess:false,
            tranType:'',
            modalDelay:false
        };
    }

    static contextTypes = {
        router:PropTypes.object
    }

    async componentWillMount(){
        const orderNo = GetQueryString('orderNo');
        const tranType = GetQueryString('tranType');
        const grade = GetQueryString('grade');
        const judgeup = GetQueryString('judgeup');
        await this.setState({tranType:tranType})
        this.getQueryPayResult(orderNo)
     }

    //查看支付状态
    getQueryPayResult(orderNo) {
        //bizParam(授权支付:授权等级, 订单支付：订单号)
        QueryPayResult(orderNo)
            .then(res=>{
                switch (res.status){
                    case 0:alert('审核中，请耐心等待');
                            //this.context.router.push({pathname:'/personalCenter'})
                        break;
                    case 2:alert('支付成功');
                        (this.state.tranType==2)?
                            (GetQueryString('isRecharge'))?
                                (GetQueryString('purchase')==2)?
                                    this.context.router.push({pathname:'/purchase'})
                                    :
                                    this.context.router.push({pathname:'/personalCenter'})
                                :
                            this.context.router.push({pathname:'/paymentSuccess',
                                query:{tranType:2,total:GetQueryString('total'),grade:GetQueryString('grade'),
                                    judgeup:GetQueryString('judgeup')}
                            })
                            :this.context.router.push({pathname:'/paymentSuccess'});
                        break;
                    default:alert('支付失败');break;
                }
            })
            .catch(err=>{
                console.log(err)
            })
    }


    render() {
        return (
            <div>
                <div className="containerNav">
                    <div style={{position:'absolute',top:'45%',width:'100%',textAlign:'center'}}>
                        <button
                            style={{padding:'3px 5px'}}
                            onClick={()=>this.getQueryPayResult(GetQueryString('orderNo'))}>查询支付状态</button>
                    </div>
                </div>
                {
                   /* this.state.modalDelay?
                        <DelayModal />
                        :null*/

                }
            </div>
        );
    }
}
